﻿using System;
using System.Windows.Forms;
using ParseExpression;
using PlotterWinForms;
using Plotter3DWinForms;

namespace MainApplication
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void DrawPlotClick(object sender, EventArgs e) {
            if (expressionParser.NumVariables == 1)
            {
                var plotForm = new PlotForm();
                ParsedFunction parsedFunction = expressionParser.BuildFunc();
                plotForm.Plotter.Plot(new Plot2dFixedY
                                          {
                                              Y = x => parsedFunction.GetValue(new[] {x}),
                                              XMin = double.Parse(textBox1.Text), XMax = double.Parse(textBox2.Text),
                                              YMin = double.Parse(textBox4.Text), YMax = double.Parse(textBox3.Text),
                                          });
                plotForm.Show();
            }
            else
            {
                var plot3dForm = new Plot3dForm();
                ParsedFunction parsedFunction = expressionParser.BuildFunc();
                plot3dForm.Plotter3D.Plot(new Plot3d
                {
                    Z = (x, y) => parsedFunction.GetValue(new[] {x, y}),
                    XMin = double.Parse(textBox1.Text),
                    XMax = double.Parse(textBox2.Text),
                    YMin = double.Parse(textBox4.Text),
                    YMax = double.Parse(textBox3.Text),
                });
                plot3dForm.Show();
            }
        }       
    }
}
